/**
 * @param {*} formData form数据
 * @param [*] formRule form规则
 * @description 表单验证
 * @description formRule: [{}] => {} => name: '字段名', errorTip: '异常提示文案', isArrayObject: 数组对象格式, objectListKay: ['对象内需要验证的字段数组', 'age'， 'name']
 */
export function formVaildation(formData, formRule) {
	return new Promise((resolve, reject) => {
		for (let i = 0; i < formRule.length; i++) {
			// 常规值是否为空
			let formRuleItem = formRule[i];
			let formDataItem = formData[formRuleItem.name];
			if (formData[formRuleItem.name] == undefined || formData[formRuleItem.name] == null || formData[formRuleItem
					.name] == '') {
				uni.showToast({
					title: formRuleItem.errorTip,
					icon: 'none'
				})
				console.log('异常', formRuleItem.errorTip);
				reject();
				return; // 异常终止，弹出提示
			}
			// 数组对象【对象可能需要判断多值】，所以rule的值需要是数组key：【'name', 'age', ...]
			if (formRuleItem.isArrayObject) {
				for (let dataI = 0; dataI < formDataItem.length; dataI++) {
					console.log('formDataItem[dataI]', formDataItem[dataI])
					let arrayObjectItem = formDataItem[dataI];
					for (let itemI = 0; itemI < formRuleItem.objectListKay.length; itemI++) {
						let itemValue = arrayObjectItem[formRuleItem.objectListKay[itemI]];
						if (itemValue == undefined || itemValue == null || itemValue == '') {
							uni.showToast({
								title: formRuleItem.errorTip,
								icon: 'none'
							})
							reject();
							console.log('异常', formRuleItem.errorTip);
							return; // 异常终止，弹出提示
						}
					}
				}
			}
		}
		console.log("规则验证通过")
		resolve(); // 正则验证通过
	})
}